﻿namespace Launcher.View

import System
import System.Drawing
import System.Windows.Forms

import Launcher.Model
import Launcher.View.Model

callable ItemSelectedEventHandler(sender as object, item as LauncherItem)

partial class LauncherView:
"""Description of LauncherView"""

	_parent as MainForm
	_model as LauncherModel

#region events

	event ItemSelected as ItemSelectedEventHandler
	
	protected virtual def OnItemSelected(item as LauncherItem):
		ItemSelected(self, item)

	event BackClicked as EventHandler
	
	protected virtual def OnBackClicked(e as EventArgs):
		BackClicked(self, e)

	event NextClicked as EventHandler
	
	protected virtual def OnNextClicked(e as EventArgs):
		NextClicked(self, e)

	event CloseClicked as EventHandler
	
	protected virtual def OnCloseClicked(e as EventArgs):
		CloseClicked(self, e)

#endregion

	[property(Visible)]			
	_visible as bool
	
	def constructor(parent as MainForm, menuModel as StartMenuModel):
		InitializeUI(parent)
		_parent = parent
		_model = LauncherModel()

		menuModel.ItemsChanged += _OnApplicationModelChanged
		_model.PageChanged += { page | _OnPageChanged(page) }

		_model.Update(menuModel.Applications)
		
	private def _OnApplicationModelChanged(menuModel as StartMenuModel):
		_model.Update(menuModel.Applications.Sort())
		UpdateShape()

	private def _OnPageChanged(page):
		_backBtn.Visible = not _model.IsFirst()
		_nextBtn.Visible = not _model.IsLast()
		Organize()

	def Draw(e as PaintEventArgs, formSize as Size):
		return if not _visible
		_shape.Draw(e, formSize)
		DrawControls(e)

	def MouseClick(sender as object, e as MouseEventArgs):
		DispatchControlsMouseClick(sender, e)
		
	def MouseMove(sender as object, e as MouseEventArgs):
		DispatchControlsMouseMove(sender, e)

	def NextPage():
		_model.Next()
		
	def BackPage():
		_model.Back()
